feat: β¨ Add AI Export integration for log analysis #469
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π― Overview
This PR adds AI Export functionality to Log Viewer, allowing users to quickly send error logs to AI assistants (ChatGPT and Claude) for analysis and debugging assistance.
β¨ Features
π§ Configuration
πΈ Screenshots
Ask AI Button in Log Entry
The new "Ask AI" button appears on each log entry
AI Provider Dropdown
Users can choose between ChatGPT, Claude, or copy as markdown
prompt pre-populated with the log formatted in ChatGPT.
Visual feedback when markdown is copied to clipboard
How it Works
β Testing
β’ Added comprehensive test coverage for all new functionality
β’ Feature tests for API endpoints with rate limiting
β’ Unit tests for services and providers
β’ All tests passing
β AI Export Providers Endpoint β returns list of available providers
β AI Export Providers Endpoint β returns 403 when feature is disabled
β AI Export Endpoint β validates required fields
β AI Export Endpoint β rejects invalid provider
β AI Export Endpoint β enforces rate limiting
β AI Export Endpoint β returns 404 when log not found
β AI Export Endpoint β returns 403 when feature is disabled
β AI Export Endpoint β returns correct response structure when successful
β Copy as Markdown Endpoint β validates required fields
β Copy as Markdown Endpoint β returns 404 when log not found
β Copy as Markdown Endpoint β returns markdown when successful
β Copy as Markdown Endpoint β returns 403 when feature is disabled
π Implementation Details
Backend
β’ New Controller: AiExportController with three endpoints
β’ GET /api/ai/providers - Lists available AI providers
β’ POST /api/ai/export - Exports log to selected AI provider
β’ POST /api/ai/copy-markdown - Returns formatted markdown
β’ Service Layer: AiExportService handles formatting and sanitization
β’ Provider Interface: Extensible design for adding new AI providers
β’ Security: Automatic sanitization of sensitive patterns including:
β’ Passwords and API keys
β’ JWT tokens
β’ Database credentials
β’ Email addresses (optionally)
Frontend
β’ Vue Component: AskAiButton.vue with dropdown UI
β’ Pinia Store: State management for AI providers
β’ Integration: Seamlessly integrated into BaseLogTable.vue
β’ User Feedback: Toast notifications for success/error states
π How to Use
LOG_VIEWER_AI_EXPORT_ENABLED=true
π Code Quality
β’ β Laravel Pint formatting applied
β’ β Follows existing code patterns and conventions
β’ β No breaking changes
β’ β Backward compatible
β’ β Feature can be completely disabled if not needed
π¨ UI/UX Considerations
β’ Non-intrusive button placement
β’ Clear visual feedback
β’ Responsive design
β’ Keyboard accessible
β’ Follows existing Log Viewer design patterns
π Performance Impact
β’ Minimal - feature is lazy loaded
β’ No impact when disabled
β’ Efficient markdown generation
β’ Rate limiting prevents abuse
π Privacy & Security
β’ All processing happens client-side
β’ No data is sent to any servers (only formatted for AI providers)
β’ Sensitive data is sanitized before export
β’ Users maintain full control over what gets sent to AI
π Documentation
The feature is self-documenting through:
β’ Clear configuration options in config/log-viewer.php
β’ Inline code comments
β’ Comprehensive test suite showing usage patterns
This feature enhances the debugging experience by leveraging AI assistants to help developers quickly understand and resolve errors in their Laravel applications.